<template>
  <div class="top-container">
    <h1>新闻网站</h1>
    <nav>
      <ul>
        <li><a href="#" @click.prevent="setActive('domestic')">国内</a></li>
        <li><a href="#" @click.prevent="setActive('entertainment')">娱乐</a></li>
        <li><a href="#" @click.prevent="setActive('sport')">体育</a></li>
        <li><a href="#">关于我们</a></li>
      </ul>
    </nav>
  </div>
</template>

<script setup lang="ts">
import { inject } from 'vue';

// 接收从父组件传递的activeCategory更新函数
const setActive = inject<(category: string) => void>('setActive');
</script>

<style scoped>
.top-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #2c3e50;
  color: #fff;
  padding: 15px 20px;
  border-radius: 4px 4px 0 0;
}

.top-container h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.5px;
}

.top-container nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
}

.top-container nav ul li {
  margin-left: 25px;
}

.top-container nav ul li a {
  color: #fff;
  text-decoration: none;
  font-size: 16px;
  transition: color 0.2s;
}

.top-container nav ul li a:hover {
  color: #ddd;
  text-decoration: underline;
}

@media (max-width: 768px) {
  .top-container {
    flex-direction: column;
    gap: 10px;
  }
  
  .top-container nav ul li {
    margin: 0 10px;
  }
}
</style>
    